home *** CD-ROM | disk | FTP | other *** search
- /******************************************************************************
- * tex1.c
- ******************************************************************************
- *
- * Purpose:
- * Descriptional text.
- *
- * Authors:
- * Michael Teschner and Christian Henn
- *
- * Note:
- * None.
- *
- * Revisions:
- * 10.11.93 micha Created file.
- *
- ******************************************************************************
- *
- * COPYRIGHT (C) 1992, 1993, 1994
- *
- * BY CHRISTIAN HENN M.E. MUELLER-INSTITUTE FOR MICROSCOPY (MIM)
- * HENN@COMP.BIOZ.UNIBAS.CH CH-4056 BASEL, SWITZERLAND
- *
- * AND MICHAEL WALDHERR-TESCHNER SILICON GRAPHICS INDUSTRIES (SGI)
- * MICHA@BASEL.SGI.COM CH-4125 RIEHEN, SWITZERLAND
- *
- ******************************************************************************
- *
- * PERMISSION TO USE, COPY, MODIFY AND DISTRIBUTE THIS SOFTWARE AND ITS DOCU-
- * MENTATION FOR THE PURPOSE OF RESEARCH, DEVELOPMENT AND EDUCATION IS HEREBY
- * GRANTED FREE OF CHARGE, SUBJECT TO THE FOLLOWING RESTRICTIONS:
- *
- * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, EXPRESS,
- * IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF DESIGN,
- * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, OR ARISING FROM A
- * COURSE OF DEALING, USAGE OR TRADE PRACTICE.
- *
- * IN NO EVENT SHALL SILICON GRAPHICS OR THE M.E. MUELLER-INSTITUTE BE LIABLE
- * FOR ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
- * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
- * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
- * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
- * THIS SOFTWARE.
- *
- ******************************************************************************
- */
- /*
- * sptexture -
- * Stapuft comatible texture mapping support
- *
- * Paul Haeberli - 1989
- */
- #include "stdio.h"
- #include "gl.h"
- #include "math.h"
-
- unsigned long *longimagedata();
-
- static expandrow();
- static setalpha();
- static copybw();
- static interleaverow();
-
- /*
- * generic texture stuff
- *
- */
- typedef struct vect {
- float x, y, z, w;
- } vect;
-
-
- /*
- * real texture mapping functions
- *
- *
- */
- static int firsted;
- static int texon;
-
- static float texps1[] = {
- TX_MINFILTER,TX_POINT,
- TX_MAGFILTER,TX_POINT,
- TX_NULL
- };
-
- static float texps2[] = {
- TX_MINFILTER,TX_MIPMAP_BILINEAR,
- TX_MAGFILTER,TX_BILINEAR,
- TX_NULL
- };
-
- int high_tex;
- unsigned long img1[ 80*256];
-
- sbr_tread(name, texno)
- char *name;
- int texno;
- {
- unsigned long *imagedata;
- unsigned long l1,l2,l3,l4;
- int i, xsize, ysize;
- int ix, count;
-
- static float tevps[] = {TV_MODULATE,TV_NULL};
-
-
- sizeofimage(name,&xsize,&ysize);
- printf(" size of image %d x %d y \n",xsize,ysize );
-
- imagedata = (unsigned long *)longimagedata(name);
-
- /* generate a one-component texture out of the RGB image */
- /* this would also work with a 3-component texture */
-
- count = 0;
- for( ix = 0; ix < 256*256; ix +=4){
- l1 = ( imagedata[ix] & 0x000000ff ) << 24;
- l2 = ( imagedata[ix+1] & 0x000000ff ) << 16;
- l3 = ( imagedata[ix+2] & 0x000000ff ) << 8;
- l4 = ( imagedata[ix+3] & 0x000000ff ) ;
- img1[count++] = l1 + l2 + l3 + l4;
- }
-
- texdef2d(1,1,256,256,img1,0,texps1);
- texdef2d(2,1,256,256,img1,0,texps2);
-
- tevdef(1,0,tevps);
- /* sbr_settexture(1); */
-
- }
-
- sbr_settexture(n)
- int n;
- {
- if(n==0) {
- texbind(0,0);
- tevbind(0,0);
- texon = 0;
- } else {
- if( high_tex ) texbind(0,2);
- else texbind(0,1);
- if(texon == 0) {
- tevbind(0,1);
- texon = 1;
- }
- }
- }
-
-
- /*******************************************************/
-
- /* from fastimage.c */
-
- #include <gl/image.h>
-
- #define TAGLEN (5)
- /*
- * sizeofimage -
- * return the xsize and ysize of an iris image file.
- *
- */
- sizeofimage(name, xsize, ysize)
- char *name;
- int *xsize, *ysize;
- {
- IMAGE image;
- FILE *inf;
-
- inf = fopen(name,"r");
- if(!inf) {
- fprintf(stderr,"sizeofimage: can't open image file %s\n",name);
- exit(1);
- }
- fread(&image,sizeof(IMAGE),1,inf);
- if(image.imagic != IMAGIC) {
- fprintf(stderr,"sizeofimage: bad magic number in image file\n");
- exit(1);
- }
- *xsize = image.xsize;
- *ysize = image.ysize;
- fclose(inf);
- }
-
- /*
- * longimagedata -
- * read img a B/W RGB or RGBA iris image file and return a
- * pointer to an array of longs.
- *
- */
- unsigned long *longimagedata(name)
- char *name;
- {
- unsigned long *base, *lptr;
- unsigned char *rledat, *verdat;
- long *starttab, *lengthtab;
- FILE *inf;
- IMAGE *image;
- int y, z, pos, len, tablen;
- int xsize, ysize, zsize;
- int bpp, rle, cur, badorder;
- int rlebuflen;
-
- inf = fopen(name,"r");
- if(!inf) {
- fprintf(stderr,"longimagedata: can't open image file %s\n",name);
- exit(1);
- }
- image = (IMAGE *)malloc(sizeof(IMAGE));
- fread(image,sizeof(IMAGE),1,inf);
- if(image->imagic != IMAGIC) {
- fprintf(stderr,"longimagedata: bad magic number in image file\n");
- exit(1);
- }
- rle = ISRLE(image->type);
- bpp = BPP(image->type);
- if(bpp != 1 ) {
- fprintf(stderr,"longimagedata: image must have 1 byte per pix chan\n");
- exit(1);
- }
- xsize = image->xsize;
- ysize = image->ysize;
- zsize = image->zsize;
- if(rle) {
- tablen = ysize*zsize*sizeof(long);
- starttab = (long *)malloc(tablen);
- lengthtab = (long *)malloc(tablen);
- rlebuflen = 1.05*xsize+10;
- rledat = (unsigned char *)malloc(rlebuflen);
- fseek(inf,512,SEEK_SET);
- fread(starttab,tablen,1,inf);
- fread(lengthtab,tablen,1,inf);
-
- /* check data order */
- cur = 0;
- badorder = 0;
- for(y=0; y<ysize; y++) {
- for(z=0; z<zsize; z++) {
- if(starttab[y+z*ysize]<cur) {
- badorder = 1;
- break;
- }
- cur = starttab[y+z*ysize];
- }
- if(badorder)
- break;
- }
- fseek(inf,512+2*tablen,SEEK_SET);
- cur = 512+2*tablen;
- base = (unsigned long *)
- malloc((xsize*ysize+TAGLEN)*sizeof(long));
- addlongimgtag(base,xsize,ysize);
- if(badorder) {
- for(z=0; z<zsize; z++) {
- lptr = base;
- for(y=0; y<ysize; y++) {
- if(cur != starttab[y+z*ysize]) {
- fseek(inf,starttab[y+z*ysize],SEEK_SET);
- cur = starttab[y+z*ysize];
- }
- if(lengthtab[y+z*ysize]>rlebuflen) {
- fprintf(stderr,"longimagedata: rlebuf is too small - bad poop\n");
- exit(1);
- }
- fread(rledat,lengthtab[y+z*ysize],1,inf);
- cur += lengthtab[y+z*ysize];
- expandrow(lptr,rledat,3-z);
- lptr += xsize;
- }
- }
- } else {
- lptr = base;
- for(y=0; y<ysize; y++) {
- for(z=0; z<zsize; z++) {
- if(cur != starttab[y+z*ysize]) {
- fseek(inf,starttab[y+z*ysize],SEEK_SET);
- cur = starttab[y+z*ysize];
- }
- fread(rledat,lengthtab[y+z*ysize],1,inf);
- cur += lengthtab[y+z*ysize];
- expandrow(lptr,rledat,3-z);
- }
- lptr += xsize;
- }
- }
- if(zsize == 3)
- setalpha(base,xsize*ysize);
- else if(zsize<3)
- copybw(base,xsize*ysize);
- fclose(inf);
- free(starttab);
- free(lengthtab);
- free(rledat);
- free(image);
- return base;
- } else {
- base = (unsigned long *)
- malloc((xsize*ysize+TAGLEN)*sizeof(long));
- addlongimgtag(base,xsize,ysize);
- verdat = (unsigned char *)malloc(xsize);
- fseek(inf,512,SEEK_SET);
- for(z=0; z<zsize; z++) {
- lptr = base;
- for(y=0; y<ysize; y++) {
- fread(verdat,xsize,1,inf);
- interleaverow(lptr,verdat,3-z,xsize);
- lptr += xsize;
- }
- }
- if(zsize == 3)
- setalpha(base,xsize*ysize);
- else if(zsize<3)
- copybw(base,xsize*ysize);
- fclose(inf);
- free(verdat);
- free(image);
- return base;
- }
- }
-
-
-
- /* static utility functions for longimagedata */
-
- static interleaverow(lptr,cptr,z,n)
- unsigned char *lptr, *cptr;
- int z, n;
- {
- lptr += z;
- while(n--) {
- *lptr = *cptr++;
- lptr += 4;
- }
- }
-
- static copybw(lptr,n)
- long *lptr;
- int n;
- {
- while(n>=8) {
- lptr[0] = 0xff000000+(0x010101*(lptr[0]&0xff));
- lptr[1] = 0xff000000+(0x010101*(lptr[1]&0xff));
- lptr[2] = 0xff000000+(0x010101*(lptr[2]&0xff));
- lptr[3] = 0xff000000+(0x010101*(lptr[3]&0xff));
- lptr[4] = 0xff000000+(0x010101*(lptr[4]&0xff));
- lptr[5] = 0xff000000+(0x010101*(lptr[5]&0xff));
- lptr[6] = 0xff000000+(0x010101*(lptr[6]&0xff));
- lptr[7] = 0xff000000+(0x010101*(lptr[7]&0xff));
- lptr += 8;
- n-=8;
- }
- while(n--) {
- *lptr = 0xff000000+(0x010101*(*lptr&0xff));
- lptr++;
- }
- }
- static setalpha(lptr,n)
- unsigned char *lptr;
- {
- while(n>=8) {
- lptr[0*4] = 0xff;
- lptr[1*4] = 0xff;
- lptr[2*4] = 0xff;
- lptr[3*4] = 0xff;
- lptr[4*4] = 0xff;
- lptr[5*4] = 0xff;
- lptr[6*4] = 0xff;
- lptr[7*4] = 0xff;
- lptr += 4*8;
- n -= 8;
- }
- while(n--) {
- *lptr = 0xff;
- lptr += 4;
- }
- }
- static expandrow(optr,iptr,z)
- unsigned char *optr, *iptr;
- int z;
- {
- unsigned char pixel, count;
-
- optr += z;
- while(1) {
- pixel = *iptr++;
- if ( !(count = (pixel & 0x7f)) )
- return;
- if(pixel & 0x80) {
- while(count>=8) {
- optr[0*4] = iptr[0];
- optr[1*4] = iptr[1];
- optr[2*4] = iptr[2];
- optr[3*4] = iptr[3];
- optr[4*4] = iptr[4];
- optr[5*4] = iptr[5];
- optr[6*4] = iptr[6];
- optr[7*4] = iptr[7];
- optr += 8*4;
- iptr += 8;
- count -= 8;
- }
- while(count--) {
- *optr = *iptr++;
- optr+=4;
- }
- } else {
- pixel = *iptr++;
- while(count>=8) {
- optr[0*4] = pixel;
- optr[1*4] = pixel;
- optr[2*4] = pixel;
- optr[3*4] = pixel;
- optr[4*4] = pixel;
- optr[5*4] = pixel;
- optr[6*4] = pixel;
- optr[7*4] = pixel;
- optr += 8*4;
- count -= 8;
- }
- while(count--) {
- *optr = pixel;
- optr+=4;
- }
- }
- }
- }
-
- /*
- * addlongimgtag -
- * this is used to extract image data from core dumps.
- *
- */
- addlongimgtag(dptr,xsize,ysize)
- unsigned long *dptr;
- int xsize, ysize;
- {
- dptr = dptr+(xsize*ysize);
- dptr[0] = 0x12345678;
- dptr[1] = 0x59493333;
- dptr[2] = 0x69434222;
- dptr[3] = xsize;
- dptr[4] = ysize;
- }
-
-
-
- /*mssize () {}
- zbsize () { }
- multisample () {}
- t3f () {}
- */
-
-
-